// pages/pluginprivate/pluginprivate.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    opren: {}
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (e) {
    getApp().page.onLoad(this, e);
    if (wx.getStorageSync('ACCESS_TOKEN')) {
      var recommender_id = wx.getStorageSync('recommender_id')
      console.log('已登录', recommender_id)
      if (recommender_id != '' || recommender_id != '0') {
        console.log('已登录有')
        getApp().page.bindParent1(recommender_id)
      }
      if (e.scene) {
        console.log('scene1')
        getApp().page.bindParent1(e.scene)
      }
      if (e.recommender_id) {
        console.log('recommender_id1')
        getApp().page.bindParent1(e.recommender_id)
      }
    } else {
      console.log('未登录')
      var recommender_id = wx.getStorageSync('recommender_id')
      console.log('recommender_id==', recommender_id)
      if (e.recommender_id) {
        if (recommender_id == '' || recommender_id == '0') {
          console.log('wu')
          wx.setStorageSync('recommender_id', e.recommender_id)
        }
      }
      if (e.scene) {
        if (recommender_id == '' || recommender_id == '0') {
          console.log('scenewu')
          wx.setStorageSync('recommender_id', e.scene)
        }
      }
    }
    wx.getChannelsLiveInfo({
      finderUserName: 'sphlAvG4O3eSXGd',
      complete: (res) => {
        console.log('1111', res)
        if (res.status) {
          this.setData({
            opren: res
          })
        }
      }
    }),
      this.login()

  },
  LiveInfo: function (e) {
    console.log('zhibojinlai')
    if(!wx.getStorageSync('ACCESS_TOKEN')){
      this.login()
    }else{
      var opren = this.data.opren
      if (opren.status == 2) {
        wx.openChannelsActivity({
          finderUserName: 'sphlAvG4O3eSXGd',
          feedId: opren.feedId,
          complete: (r) => {
            console.log('11112222', r)
          }
        })
      } else {
        wx.showToast({
          title: '暂未开播',
          icon: 'none',
          duration: 2000
        })        
      }
    }

  },
  login: function (e) {
    wx.getStorageSync('ACCESS_TOKEN') || getApp().page.setUserInfoShow();
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    getApp().page.onShow(this);
  },
  onReady: function (e) {
    getApp().page.onReady(this);
  },
})